﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace WpfCourse.Common
{
    public class CommandBase : ICommand
    {
        public bool CanExecute(object parameter)
        {
            if (this.DoCanExecute != null)
            {
                return this.DoCanExecute.Invoke(parameter) == true;
            }
            else
            {
                return false;
            }
        }

        public event EventHandler CanExecuteChanged;

        public void Execute(object parameter)
        {
            if (this.DoExecute != null)
            {
                this.DoExecute.Invoke(parameter);
            }
        }

        public Action<object> DoExecute { get; set; }

        public Func<object, bool> DoCanExecute { get; set; }
    }
}
